package com.foxzzz.back.tracking;

import java.util.ArrayList;
import java.util.List;

public class Solution46 {
    public List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> result = new ArrayList<>();
        List<Integer> list = new ArrayList<>();
        range(result, list, nums);
        return result;
    }

    public void range(List<List<Integer>> result, List<Integer> list, int[] nums) {
        //
        if (list.size() == nums.length) {
            result.add(new ArrayList<>(list));
        }
        for (int i = 0; i < nums.length; i++) {
            if(!list.contains(nums[i])) {
                list.add(nums[i]);
                range(result, list, nums);
                list.remove(list.size() - 1);
            }
        }

    }



    public static void main(String[] args) {
        System.out.println(new Solution46().permute(new int[]{1, 2, 3}));
    }
}
